import * as React from "react";
import {Button} from 'antd'

class ErrorBoundaryComponent extends React.Component {

    state={hasError: false,info:{}};
    componentDidCatch(error:any, info:any) {
        // Display fallback UI
        this.setState({hasError: true,info});
        // You can also log the error to an error reporting service
    }

    render() {
        if (this.state.hasError) {
            let data =JSON.stringify(this.state.info).split("\\n");
            data = data.filter(it=> it.indexOf(":")!==-1);
            data.shift();

            return <>
                <h1>Something went wrong.</h1>
                <p  style={{margin:'50px'}}>{data.map(it=><div key={it}>{it}</div>)}</p>
                <Button onClick={()=>History}>返回首页</Button>
            </>;
        }
        return this.props.children;
    }
}
export default ErrorBoundaryComponent;
